<template>
  <div>
    <el-form ref="xForm" v-model="formData" :config="formConfig">
      <el-collapse   v-model="activeNames">
        <el-collapse-item name="1">
          <template #title>
            <el-icon class="header-icon">
              <info-filled />
            </el-icon>
            常规信息
          </template>
          <el-form-item label="流程标识" :rules="[{ required: true, message: 'Id 不能为空' }]">
            <el-input type="text" v-model="formData['id']" ></el-input>
          </el-form-item>
          <el-form-item label="流程名称" :rules="[{ required: true, message: ' 流程名称不能为空' }]">
            <el-input type="text" v-model="formData['name']" ></el-input>
          </el-form-item>
          <el-form-item label="流程分类" >
            <el-select v-model="formData['processCategory']" >
              <el-option v-for="(item,index) in dict('process_type')" :value="item.value" :label="item.label">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="节点描述" >
            <el-input type="textarea" v-model="formData['documentation']" ></el-input>
          </el-form-item>
        </el-collapse-item>
        <el-collapse-item name="2">
          <template #title>
            <el-icon class="header-icon">
              <List />
            </el-icon>
            执行监听器
          </template>
          <el-form-item label="监听器" >
            <FmSelectTable v-model:value="formData['executionListener']"  title="监听器" :columns="selectcolumns" url="/process/flowable" keys="formId"  lable="formName" tableName="sysform" >
            </FmSelectTable>
          </el-form-item>
        </el-collapse-item>

      </el-collapse>
    </el-form>
    <executionListenerDialog
      v-if="dialogName === 'executionListenerDialog'"
      :element="element"
      :modeler="modeler"
      @close="finishExecutionListener"
    />
    <signalDialog
      v-if="dialogName === 'signalDialog'"
      :element="element"
      :modeler="modeler"
      @close="finishExecutionListener"
    />
  </div>
</template>

<script>
import mixinPanel from '../../common/mixinPanel'
import mixinExecutionListener from '../../common/mixinExecutionListener'
import signalDialog from '@/components/Process/components/nodePanel/property/signal.vue'
import { commonParse } from '../../common/parseElement'
import {LoadDict} from "@/utils/dict/index";
import {toRaw} from "vue";
import  store from "@/store/index"
export default {
  components: {
    signalDialog
  },
  mixins: [mixinPanel, mixinExecutionListener],
  data() {
    return {
      signalLength: 0,
      activeNames:"1",
      formData: {},
      dicts:{},
      selectcolumns:[
        {
          "label": "表单编号",//标签名称
          "index": "formId",//数据库索引
          "search": true,//是否是搜索表单
          "dataType": "text",//值值类型默认字符类型
          "addable":false
        },
        {
          "label": "表单名称",//标签名称
          "index": "formName",//数据库索引
          "search": true,//是否是搜索表单
          "dataType": "text",//值值类型默认字符类型
          "addable":false
        },
        {
          "label": "备注",//标签名称
          "index": "remark",//数据库索引
          "search": true,//是否是搜索表单
          "dataType": "text",//值值类型默认字符类型
          "addable":false
        },
      ],
    }
  },
  computed: {
    dict() {
      return function (key) {
      var dicts =store.state.dicts.dictMap.get(key);
      debugger
      if (dicts) {
        return toRaw(dicts.type[key])
      } else {
        return []
      }
    }
    },
    formConfig() {
      const _this = this
      return {
        inline: false,
        item: [
          {
            xType: 'select',
            name: 'processCategory',
            label: '流程分类',
            dic: { data: _this.categorys, label: 'dictLabel', value: 'dictValue' }
          },
          {
            xType: 'input',
            name: 'id',
            label: '流程标识key',
            rules: [{ required: true, message: 'Id 不能为空' }]
          },
          {
            xType: 'input',
            name: 'name',
            label: '流程名称'
          },
          {
            xType: 'input',
            name: 'documentation',
            label: '节点描述'
          },
          {
            xType: 'slot',
            name: 'executionListener',
            label: '执行监听器'
          },
          {
            xType: 'slot',
            name: 'signal',
            label: '信号定义'
          }
        ]
      }
    }
  },
  watch: {
    'formData.processCategory': function(val) {
      if (val === '') val = null
      this.updateProperties({ 'flowable:processCategory': val })
    }
  },
  created() {
    this.formData = commonParse(this.element)
    LoadDict(["process_type"])

  },
  methods: {
    store,
    computedSignalLength() {
      this.signalLength = this.element.businessObject.extensionElements?.values?.length ?? 0
    },
    finishSignal() {
      if (this.dialogName === 'signalDialog') {
        this.computedSignalLength()
      }
      this.dialogName = ''
    }
  }
}
</script>

<style>

</style>
